package com.rbac.web.model;

import java.util.List;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * @author gengaoliu
 */
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class PermissionTree {

  private Integer id;
  private String code;
  private String name;
  private String value;
  private PermissionType type;
  private Integer menuId;
  private Integer pId;
  private String remark;
  private PermissionAction action;
  private Integer sort;
  private String displayName;
  private String icon;
  private String path;
  private List<Integer> pIds;
  private List<Integer> menuIds;
  private List<PermissionTree> children;
  private List<PermissionTree> buttonList;
  private Meta meta;

  public void setMata(String title, String icon, Integer sort) {
    this.meta = Meta.builder().title(title).icon(icon).order(sort).build();
  }

  public boolean isTop(Integer topParentId) {
    return topParentId.equals(Optional.ofNullable(pId).orElse(0));
  }

  @Getter
  @Builder
  static class Meta {

    private String title;
    private String icon;
    private Integer order;
    private Boolean hidden;
    private List<String> buttonCodes;
  }
}
